#pragma once
#include <windows.h>
#include "IME.h"
#include "Msg.h"
#include "Misc.h"
#include "support.h"


#define _API __declspec(dllexport)

typedef void(*OnPostFn)(void* context, int width, int height, int ydir,
	int format, int type, unsigned char* pixels);


extern "C" {
	_API int				av_Init();
	_API int				av_CheckVT();
	_API bool				av_EnvCheck();

	_API int				av_Lunch(HWND hwnd, int x, int y, int clientwidth, int clientheight, wchar_t *json);
	_API void				av_Shutdown();
	_API wchar_t*			av_ListVMS();
	_API wchar_t*			av_Get_vmPath();
	_API wchar_t*			av_Get_vmStatus(wchar_t *msg);

	_API bool				av_Send_input(wchar_t *input);
	_API void				av_MouseEvent(int action, int x, int y, int type);
	_API void				av_KeyEvent(int key);
	_API void				av_Send_Msg(int type, wchar_t *msg);

	_API void				av_Set_Sensors(wchar_t *msg);
	_API void				av_Set_Gps(wchar_t *msg);

	_API bool				av_wProc(HWND hwnd, UINT uMsg, WPARAM wParam);
	_API void				av_Screenshot(int x, int y, unsigned char * argb);
}

Misc * m_Misc;
IME * m_IME;
Msg * m_Msg;
LRESULT CALLBACK myWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
HWND msgHwnd;
static bool inited;
WCHAR m_InputValue[8];
HWND createSubWindow(HWND p_window, int x, int y, int width, int height);
void destroySubWindow(HWND win);
std::wstring GetFilePosfix(wchar_t* path);

typedef bool(*p_initLibrary)(void);
typedef int(*p_FrameBuffer_setupSubWindow)(HWND id, int w, int h, float zrot);
typedef void(*p_setCallbackRotation)(void(*fn)(float));
typedef void(*p_setOpenGLDisplayRotation)(float);
typedef int(*p_FrameBuffer_removeSubWindow)(void);
typedef void(*p_repaintOpenGLDisplay)(void);
typedef int(*p_setPipename)(char *);
typedef int(*p_initOpenGLRenderer)(int, int);
typedef unsigned char*(*p_Screenshot)(void);
typedef bool (*p_destroyOpenGLSubwindow)(void);

p_initLibrary initLibrary;
p_FrameBuffer_setupSubWindow FrameBuffer_setupSubWindow;
p_setCallbackRotation setCallbackRotation;
p_setOpenGLDisplayRotation setOpenGLDisplayRotation;
p_FrameBuffer_removeSubWindow FrameBuffer_removeSubWindow;
p_repaintOpenGLDisplay repaintOpenGLDisplay;
p_setPipename setPipename;
p_initOpenGLRenderer initOpenGLRenderer;
p_Screenshot Screenshot;
p_destroyOpenGLSubwindow destroyOpenGLSubwindow;